package cn.yunhe.demo.dao;

import cn.yunhe.demo.entity.Emp;
import cn.yunhe.demo.factory.BaseDB;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class Empdao implements IEmpDao {
    Connection conn=null;
    PreparedStatement psmt=null;
    ResultSet rs=null;
    @Override
    public List<Emp> allEmp() {
        List<Emp> list=new ArrayList<>();
        try {
            conn= BaseDB.getConn();
            String sql="select * from emp";
            psmt=conn.prepareStatement(sql);
            rs=psmt.executeQuery();
            while (rs.next()){
                Emp emp = new Emp(rs.getInt("empno"),rs.getString("ename"),rs.getString("job"),rs.getFloat("sal"));
                list.add(emp);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return list;
    }
}
